(function(window, document) {
    angular
        .module('app')
        .controller('accountDaylistController', accountDaylistController);

    accountDaylistController.$inject = [
        'accountDaylistFactory',
        'uidFactory',
        '$stateParams'
    ];

    /**
     * 帐号天数列表控制器
     * @param  {service} accountDaylistFactory 自定义服务
     * @param  {service} uidFactory            自定义服务
     * @param  {service} $stateParams          uirouter服务
     * @return null
     */
    function accountDaylistController(accountDaylistFactory, uidFactory, $stateParams) {
        var vm = this;
        var uid = uidFactory.getUid() || 1;
        var accountid = parseInt($stateParams.accountid);

        // 设置获取帐号天数列表所需参数
        accountDaylistFactory.setUid(uid);
        accountDaylistFactory.setAccountid(accountid);

        // 获得数据
        accountDaylistFactory.accountDaylistPromise().then(accountDaylistPromiseSuccess, accountDaylistPromiseFail);

        /**
         * 获取帐号天数列表
         * @param  {object} data 后台接口返回值
         * @return null
         */
        function accountDaylistPromiseSuccess (data) {
            switch(data.returncode) {
                case 0:
                    vm.list = data.list;
                    break;
                case -1:
                    alert('已购买同类型账号，到期后才能再次购买哦！');
                    history.go(-1);
                    break;
                case -999:
                    alert('系统维护升级中！');
                    break;
            }
        }

        /**
         * 获取帐号天数列表失败
         * @param  {object} err 错误返回值
         * @return null
         */
        function accountDaylistPromiseFail (err) {
            alert(err);
        }

    }
})(window, document);
